package com.ants.boot.wx.controller;

import com.ants.boot.core.Response;
import com.ants.boot.core.annotation.Log;
import com.ants.boot.wx.domain.WxSuggest;
import com.ants.boot.wx.dto.wxsuggest.AddWxSuggestDto;
import com.ants.boot.wx.dto.wxsuggest.DelWxSuggestDto;
import com.ants.boot.wx.dto.wxsuggest.QueryWxSuggestDto;
import com.ants.boot.wx.service.WxSuggestService;
import com.ants.boot.wx.vo.wxsuggest.WxSuggestVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 蚂蚁会花呗
 * @date 2022/6/1 10:56
 */
@RestController
@RequestMapping("wx/suggest")
@Api(tags = "小程序建议意见")
public class WxSuggestController {

    @Autowired
    private WxSuggestService wxSuggestService;


    /**
     * 日志分页
     * @param dto
     * @return
     */
    @PostMapping("page_info")
    @Log(module = "意见管理",operate = "查询、搜索")
    @ApiOperation(value = "意见分页",notes = "意见查询搜索")
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功！",response = WxSuggestVo.class)
    })
    public Response pageInfo(@RequestBody @Validated QueryWxSuggestDto dto){
        IPage<WxSuggest> iPage = wxSuggestService.pageInfo(dto);
        return Response.okData(iPage);
    }




    /**
     * 添加意见建议
     * @return
     */
    @PostMapping("add_suggest")
    @ApiOperation(value = "添加建议",notes = "小程序建议意见反馈")
    @ApiResponses({
            @ApiResponse(code = 200,message = "操作成功！")
    })
    public Response addSuggest(@RequestBody @Validated AddWxSuggestDto dto){
        boolean result = wxSuggestService.addSuggest(dto);
        if (!result){
            return Response.fail();
        }
        return Response.ok();
    }

    /**
     * 删除意见建议
     * @return
     */
    @PostMapping("del_suggest")
    @ApiOperation(value = "删除建议",notes = "删除小程序建议意见反馈")
    @ApiResponses({
            @ApiResponse(code = 200,message = "操作成功！")
    })
    public Response delSuggest(@RequestBody @Validated DelWxSuggestDto dto){
        boolean result = wxSuggestService.delSuggest(dto.getIds());
        if (!result){
            return Response.fail();
        }
        return Response.ok();
    }


}
